//
//  HLMainController.swift
//  MyWeiBo
//
//  Created by fannie on 16/3/19.
//  Copyright © 2016年 fannie. All rights reserved.
//

import UIKit

class HLMainController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let mainTabBar=HLMainTabBar()
        mainTabBar.btnClick={
            print("按钮被点击")
        }
        self.setValue(mainTabBar, forKey: "tabBar")
        addChildViewControllers()
    }
    
    func addChildViewControllers() {
        let homeVC=HLHomeViewController()
        addChildViewController(homeVC, title: "首页", imageName:"tabbar_home")
        
        let messageVC=HLMessageViewController()
        addChildViewController(messageVC, title: "消息", imageName: "tabbar_message_center")
        
        let discoverVC=HLDiscoverViewController()
        addChildViewController(discoverVC, title: "发现", imageName: "tabbar_discover")
        
        let profileVC=HLProFileViewController()
        addChildViewController(profileVC, title: "我", imageName: "tabbar_profile")
    }

    func addChildViewController(controller: UIViewController, title:String, imageName:String) {
        
        controller.title=title
        controller.tabBarItem.image=UIImage(named: imageName)
        
        let imageSelectName=imageName+"_highlighted"
        controller.tabBarItem.selectedImage=UIImage(named: imageSelectName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
        
        addChildViewController(UINavigationController(rootViewController: controller))
    }

}
